<div class="layuimini-container">
    <div class="layuimini-main">
        <div>
            <button class="layui-btn layui-btn-normal layui-btn-sm" id="user">导入机器人</button>
            <button class="layui-btn layui-btn-normal layui-btn-sm" data-open="system.robots_list/addrobot" data-title="批量添加会员机器人">批量添加机器人</button>
            <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="downloadrobot()" data-title="下载导入模板">下载导入模板</button>
            <div class="layui-inline" onclick="showHelp()" style="float:right;display: block;height:30px;cursor: pointer;">
                <img  style="height:100%;" src="https://direct-file.oss-cn-beijing.aliyuncs.com/admin/problem.png" alt="">
            </div>
        </div>
        <table id="currentTable" class="layui-table layui-hide"
               data-auth-add="{:auth('system.robots_list/add')}"
               data-auth-edit="{:auth('system.robots_list/edit')}"
               data-auth-delete="{:auth('system.robots_list/delete')}"
               lay-filter="currentTable">
        </table>
    </div>
</div>

<script>
    
    layui.use('upload', function(){
        var upload = layui.upload;
        
        //执行实例
        var uploadInst = upload.render({
            elem: '#user' //绑定元素
            ,url: "robotimport", //上传接口
            accept:'file',
            done: function (res) {

                if (res.status  == 200 ) {
                    if (res.data.length>0) {
                        let arr = res.data;
                        let overlap = arr.join(',')


                        layer.open({
                            title:'导入成功',
                            type: 1
                            ,offset: 'auth' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                            ,id: 'layerDemoauth' //防止重复弹出
                            ,content: '<div style="padding: 20px 100px;">'+ `重复名称：`+overlap +'</div>'
                            ,btn: '关闭'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                            layer.closeAll();
                                window.location.reload();
                            }
                        });

                    
                           
                    }else{
                        layer.alert('导入成功');
                        window.location.reload();
                    }
                }else{
                    layer.alert("导入失败");
                }

                
            //上传完毕回调
            }
            ,error: function () {
            //请求异常回调
            }
        });
    });
    function showHelp()
    {
        layer.open({
            type: 2,
            title:"帮助",
            area: ['1016px', '700px'],
            content: '/admin/index/assist?type=robot' //iframe的url
        });
    }
    function downloadrobot ()
    {
        window.open("https://direct-file.oss-cn-beijing.aliyuncs.com/admin/import-template-robot.xlsx");
    }
</script>
